package SegmentTree._732_MyCalendarIII;

import java.util.TreeMap;

public class MyCalendarThree {
    TreeMap<Integer,Integer> delta;
    public MyCalendarThree() {
        delta = new TreeMap<>();
    }

    public int book(int start, int end) {
        delta.put(start, delta.getOrDefault(start, 0) + 1);
        delta.put(end, delta.getOrDefault(end, 0) - 1);
        int max = 0;
        int counts = 0;
        for (int count : delta.values()) {
            counts += count;
            max = Math.max(counts, max);
        }
        return max;
    }
}
